*generate lower and upper bounds using the experiment data 
************************************************************************************************************
**************************************************Figure S.2************************************************
************************************************************************************************************
use data_long,clear

*Estimate coefficient on price when discount isn't too different

bys cs: egen sddiscount = sd(discount)
xtile sdquant = sddiscount, nq(4)

rename initial_price price
clogit chosen price discount rating if condition == 0 & sdquant == 1, group(cs)

local R = 10000


*Now we know the full utility function

*Let's loop through and do R simulations
*In each simulation, compute U and VU for every good
gen othercount = 0
gen bestbothcount = 0
forvalues r = 1/`R' {
display "Draw is `r'"
set seed 400`r'
qui gen gumbel = -ln(-ln(runiform())) 
qui gen VU = _b[price]*price+_b[rating]*rating+gumbel
qui gen U = _b[price]*(price+discount)+_b[rating]*rating + gumbel
*For upper bound, compute:
*P(U_ik > U_ij and VU_ik > VU_ij for some k)
*i.e. does some other good have higher utility and higher visible utility?
*Sort by utility, check each good with higher utility and see if it has higher visible utility
gsort cs -U
by cs: gen Urank = _n
qui gen otherbetter = 0
qui replace otherbetter = 1 if Urank == 2 & VU[_n-1] > VU
qui replace otherbetter = 1 if Urank == 3 & ((VU[_n-1]>VU) | (VU[_n-2]>VU))
qui replace othercount = othercount + otherbetter
*For lower bound, compute:
*P(U_ij > U_ik and VU_ij > VU_ik for all k)
*i.e. is good j highest in terms of both utility and visible utility?
gsort cs -VU
by cs: gen VUrank = _n
gen bestboth = (Urank == 1)*(VUrank == 1)
replace bestbothcount = bestbothcount + bestboth
drop Urank VUrank bestboth otherbetter VU U gumbel
}

gen Pother = othercount / `R'
gen Pbestboth = bestbothcount / `R'

gen UB = 1-Pother
gen LB = Pbestboth
sort LB
gen xaxis = _n
save boundtest_all,replace 

use boundtest_all,clear
keep if condition==0
sort cs option_id
outsheet cs option_id chosen price discount rating click LB UB using data_boundtest.csv, comma replace

